package com.easycode.devtool.domain;

import com.easycode.devtool.util.StringUtils;
import com.google.common.base.Strings;

import java.util.List;

/**
 * Created by carter on 2017/2/7. Copyright © 2016 －2017 深圳布谷鸟信息技术有限公司
 */
public class FieldModel {

    private String fieldName ="";
    private String fieldComment ="";
    private String fieldType ="";
    private int fieldLength =0;
    private String fieldDefaultValue ="";
    private String formHtmlType ="";//添加或者编辑页面对应的标签类型

    public FieldModel() {
    }

    public FieldModel(String fieldName, String fieldComment, String fieldType, int fieldLength) {
        this.fieldName = fieldName;
        setFieldComment(fieldComment);
        this.fieldType = fieldType;
        this.fieldLength = fieldLength;
    }

    public String getFieldName() {
        return fieldName;
    }

    public String getCamelFieldName(){

        StringBuffer stringBuffer = new StringBuffer();
        List<String> stringList = StringUtils.split2List(fieldName, "_");

        for(int i=0;i<stringList.size();i++)
        {
            String tem = stringList.get(i);
            if(i>0)
            {
                tem = tem.substring(0,1).toUpperCase()+tem.substring(1,tem.length()).toLowerCase();
            }else {
                tem = tem.toLowerCase();
            }
            stringBuffer.append(tem);

        }

        return stringBuffer.toString();

    }


    public String getEntityName(){

        StringBuffer stringBuffer = new StringBuffer();
        List<String> stringList = StringUtils.split2List(fieldName, "_");

        for(int i=0;i<stringList.size();i++)
        {
            String tem = stringList.get(i);
            tem = tem.substring(0,1).toUpperCase()+tem.substring(1,tem.length()).toLowerCase();
            stringBuffer.append(tem);

        }

        return stringBuffer.toString();

    }


    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldComment() {
        return fieldComment;
    }

    public void setFieldComment(String fieldComment) {
        if("id".equalsIgnoreCase(getFieldName()) && Strings.isNullOrEmpty(getFieldComment()))
        {
            this.fieldComment = "主键ID";
        }
        else
        {
            this.fieldComment =fieldComment;
        }
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public int getFieldLength() {
        return fieldLength;
    }

    public void setFieldLength(int fieldLength) {
        this.fieldLength = fieldLength;
    }

    public String getFieldDefaultValue() {
        return fieldDefaultValue;
    }

    public void setFieldDefaultValue(String fieldDefaultValue) {
        this.fieldDefaultValue = fieldDefaultValue;
    }

    public String getFormHtmlType() {
        return formHtmlType;
    }

    public void setFormHtmlType(String formHtmlType) {
        this.formHtmlType = formHtmlType;
    }


//    public static void main(String[] args) {
//
//        FieldModel fieldModel = new FieldModel();
//        fieldModel.setFieldName("type_value");
//        System.out.println(fieldModel.getCamelFieldName());
//
//        fieldModel.setFieldName("type_value_text");
//        System.out.println(fieldModel.getCamelFieldName());
//
//        fieldModel.setFieldName("type");
//        System.out.println(fieldModel.getCamelFieldName());
//
//
//        fieldModel.setFieldName("ID");
//        System.out.println(fieldModel.getCamelFieldName());
//
//    }


}
